# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[GenericContainer.__init__(self, str(year), type_=type_, **kw)
self.year = year
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7548e8c>}
nname: 140
n 140(None)[return img_list
]:
	i: 96(AL), 139()
	o: 

nname: 139
n 139(None)[]:
	i: 105(AF), 112()
	o: 140()

nname: 112
n 112(None)[for i in img_list:
]:
	i: 105(for)
	o: 139()

nname: 105
n 105(None)[]:
	i: 96(loop)
	o: 112(for), 139(AF)

nname: 96
n 96(None)[del _[1]
for img_list in xrange(1, 13):
]:
	i: 0(AF), 93()
	o: 105(loop), 140(AL)

nname: 93
n 93(None)[]:
	i: 23(AF), 42()
	o: 96()

nname: 42
n 42(None)[for d in xrange(1, 30):
]:
	i: 23(for)
	o: 93()

nname: 23
n 23(None)[for m in xrange(1, 13):
]:
	i: 0(for)
	o: 42(for), 93(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 23(for), 96(AF)

nname: 140
n 140(None)[return img_list
]:
	i: 112()
	o: 

nname: 112
n 112(None)[for i in img_list:
	pass]:
	i: 96(for)
	o: 140()

nname: 96
n 96(None)[del _[1]
for img_list in xrange(1, 13):
]:
	i: 0(AF), 23(AF), 42()
	o: 112(for)

nname: 42
n 42(None)[for d in xrange(1, 30):
]:
	i: 23(for)
	o: 96()

nname: 23
n 23(None)[for m in xrange(1, 13):
]:
	i: 0(for)
	o: 42(for), 96(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 23(for), 96(AF)

nname: 140
n 140(None)[return img_list
]:
	i: 96()
	o: 

nname: 96
n 96(None)[del _[1]
for img_list in xrange(1, 13):
for i in img_list:
	pass]:
	i: 0(AF), 23(AF), 42()
	o: 140()

nname: 42
n 42(None)[for d in xrange(1, 30):
]:
	i: 23(for)
	o: 96()

nname: 23
n 23(None)[for m in xrange(1, 13):
]:
	i: 0(for)
	o: 42(for), 96(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 23(for), 96(AF)

nname: 96
n 96(None)[del _[1]
for img_list in xrange(1, 13):
for i in img_list:
	passreturn img_list
]:
	i: 0(AF), 23(AF), 42()
	o: 

nname: 42
n 42(None)[for d in xrange(1, 30):
]:
	i: 23(for)
	o: 96()

nname: 23
n 23(None)[for m in xrange(1, 13):
]:
	i: 0(for)
	o: 42(for), 96(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 23(for), 96(AF)

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a62c>, 96: <unpyclib.structure.node instance at 0xb754a8ac>, 42: <unpyclib.structure.node instance at 0xb754a60c>, 23: <unpyclib.structure.node instance at 0xb754a50c>}
nname: 6
n 6(None)[def __init__(self, year, type_='dir', **kw):
	GenericContainer.__init__(self, str(year), type_=type_, **kw)
	self.year = year

def browse(self):
	pass

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb75488ec>}
nname: 0
n 0(None)[GenericContainer.__init__(self, 'Dilbert comics', type_='dir')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7548d0c>}
nname: 6
n 6(None)[def __init__(self):
	GenericContainer.__init__(self, 'Dilbert comics', type_='dir')

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb754898c>}
nname: 0
n 0(None)[GenericContainer.__init__(self, 'Monsieur le chien', type_='dir', **kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754adec>}
nname: 96
n 96(None)[return self.base_uri + data[idx:].split('"', 1)[0]
]:
	i: 49(), 78(), 94(AE)
	o: 

nname: 94
n 94(None)[]:
	i: 68(f)
	o: 96(AE)

nname: 78
n 78(None)[print 'No data'
]:
	i: 68(t)
	o: 96()

nname: 68
n 68(<dummy_ex3> EXC_MATCH ValueError)[]:
	i: 0(except)
	o: 78(t), 94(f)

nname: 49
n 49(None)[idx = data.index('i/planches/')
]:
	i: 0(try)
	o: 96()

nname: 0
n 0(None)[real_uri = self.uri + str(num)
web = urllib.urlopen(real_uri)
data = web.read()
]:
	i: 
	o: 49(try), 68(except)

nname: 68
n 68(None)[except ValueError:
	print 'No data'
return self.base_uri + data[idx:].split('"', 1)[0]
]:
	i: 0()
	o: 

nname: 0
n 0(None)[real_uri = self.uri + str(num)
web = urllib.urlopen(real_uri)
data = web.read()
try:
	idx = data.index('i/planches/')
]:
	i: 
	o: 68()

nname: 0
n 0(None)[real_uri = self.uri + str(num)
web = urllib.urlopen(real_uri)
data = web.read()
try:
	idx = data.index('i/planches/')
except ValueError:
	print 'No data'
return self.base_uri + data[idx:].split('"', 1)[0]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754aacc>}
nname: 6
n 6(None)[__metaclass__ = MetaSingleton
max_idx = 290
base_uri = 'http://monsieur-le-chien.fr/'
uri = base_uri + 'index.php?planche='
def __init__(self, **kw):
	GenericContainer.__init__(self, 'Monsieur le chien', type_='dir', **kw)

def _num2jpg(self, num):
	real_uri = self.uri + str(num)
	web = urllib.urlopen(real_uri)
	data = web.read()
	try:
		idx = data.index('i/planches/')
	except ValueError:
		print 'No data'
	return self.base_uri + data[idx:].split('"', 1)[0]

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7548a8c>}
nname: 172
n 172(None)[self.uri = uri
self._pic_uri = None
ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
return None
]:
	i: 157(), 171()
	o: 

nname: 171
n 171(None)[]:
	i: 124(f)
	o: 172()

nname: 157
n 157(None)[uri += '/'
]:
	i: 124(t)
	o: 172()

nname: 124
n 124(uri[-1] != '/')[uri = self.base_site % prefix + base
]:
	i: 12(), 121()
	o: 157(t), 171(f)

nname: 121
n 121(None)[name = 'Latest'
]:
	i: 106(), 117()
	o: 124()

nname: 117
n 117(None)[]:
	i: 94(f)
	o: 121()

nname: 106
n 106(None)[]:
	i: 94(t)
	o: 121()

nname: 94
n 94(base)[prefix = ''
]:
	i: 59(), 84()
	o: 106(t), 117(f)

nname: 84
n 84(None)[self._number = None
]:
	i: 43(f)
	o: 94()

nname: 59
n 59(None)[base = str(base)
self._number = base
]:
	i: 43(t)
	o: 94()

nname: 43
n 43(isinstance(base, int))[]:
	i: 0(f)
	o: 59(t), 84(f)

nname: 12
n 12(None)[base = 'comic/random'
prefix = 'dynamic.'
name = 'Random Episode'
self._number = None
]:
	i: 0(t)
	o: 124()

nname: 0
n 0(base is None)[]:
	i: 
	o: 12(t), 43(f)

nname: 124
n 124(None)[uri = self.base_site % prefix + base
if uri[-1] != '/':
	uri += '/'
self.uri = uri
self._pic_uri = None
ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
return None
]:
	i: 12(), 121()
	o: 

nname: 121
n 121(None)[name = 'Latest'
]:
	i: 43()
	o: 124()

nname: 43
n 43(None)[if isinstance(base, int):
	base = str(base)
	self._number = base
else:
	self._number = None
prefix = ''
if base:
	pass
]:
	i: 0(f)
	o: 121()

nname: 12
n 12(None)[base = 'comic/random'
prefix = 'dynamic.'
name = 'Random Episode'
self._number = None
]:
	i: 0(t)
	o: 124()

nname: 0
n 0(base is None)[]:
	i: 
	o: 12(t), 43(f)

nname: 124
n 124(None)[uri = self.base_site % prefix + base
if uri[-1] != '/':
	uri += '/'
self.uri = uri
self._pic_uri = None
ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
return None
]:
	i: 12(), 43()
	o: 

nname: 43
n 43(None)[if isinstance(base, int):
	base = str(base)
	self._number = base
else:
	self._number = None
prefix = ''
if base:
	pass
name = 'Latest'
]:
	i: 0(f)
	o: 124()

nname: 12
n 12(None)[base = 'comic/random'
prefix = 'dynamic.'
name = 'Random Episode'
self._number = None
]:
	i: 0(t)
	o: 124()

nname: 0
n 0(base is None)[]:
	i: 
	o: 12(t), 43(f)

nname: 0
n 0(None)[if base is None:
	base = 'comic/random'
	prefix = 'dynamic.'
	name = 'Random Episode'
	self._number = None
else:
	if isinstance(base, int):
		base = str(base)
		self._number = base
	else:
		self._number = None
	prefix = ''
	if base:
		pass
	name = 'Latest'
uri = self.base_site % prefix + base
if uri[-1] != '/':
	uri += '/'
self.uri = uri
self._pic_uri = None
ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754d78c>}
nname: 0
n 0(None)[return '<%s %s>' % (self.name, self.__class__.__name__)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a30c>}
nname: 0
n 0(None)[site = urllib.urlopen(self.uri)
return site.read()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a9cc>}
nname: 0
n 0(None)[data = self._get_data()
idx = data.index(prefix) + len(prefix)
substring = data[idx:idx + lookup_size]
return substring[substring.index('http'):substring.index('</')]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a5cc>}
nname: 100
n 100(None)[return self._number
]:
	i: 15(AL), 95(), 99()
	o: 

nname: 99
n 99(None)[]:
	i: 0(f)
	o: 100()

nname: 95
n 95(None)[]:
	i: 34(AF), 91()
	o: 100()

nname: 91
n 91(None)[]:
	i: 56(f), 71()
	o: 95()

nname: 71
n 71(None)[self._number = int(subpart)
break
continue
]:
	i: 56(t)
	o: 91()

nname: 56
n 56(subpart.isdigit())[for subpart in reversed(full_uri.split('/')):
]:
	i: 34(for)
	o: 71(t), 91(f)

nname: 34
n 34(None)[]:
	i: 15(loop)
	o: 56(for), 95(AF)

nname: 15
n 15(None)[full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
]:
	i: 0(t)
	o: 34(loop), 100(AL)

nname: 0
n 0(self._number is None)[]:
	i: 
	o: 15(t), 99(f)

nname: 100
n 100(None)[return self._number
]:
	i: 15(AL), 34(AF), 56(), 0(f)
	o: 

nname: 56
n 56(None)[for subpart in reversed(full_uri.split('/')):
if subpart.isdigit():
	self._number = int(subpart)
	break
	continue
]:
	i: 34(for)
	o: 100()

nname: 34
n 34(None)[]:
	i: 15(loop)
	o: 56(for), 100(AF)

nname: 15
n 15(None)[full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
]:
	i: 0(t)
	o: 34(loop), 100(AL)

nname: 0
n 0(self._number is None)[]:
	i: 
	o: 15(t), 100(f)

nname: 100
n 100(None)[return self._number
]:
	i: 56(), 0(f)
	o: 

nname: 56
n 56(None)[for subpart in reversed(full_uri.split('/')):
	if subpart.isdigit():
		self._number = int(subpart)
		break
		continue
]:
	i: 15(for)
	o: 100()

nname: 15
n 15(None)[full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
]:
	i: 0(t)
	o: 56(for)

nname: 0
n 0(self._number is None)[]:
	i: 
	o: 15(t), 100(f)

nname: 100
n 100(None)[return self._number
]:
	i: 15(), 0(f)
	o: 

nname: 15
n 15(None)[full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
for subpart in reversed(full_uri.split('/')):
	if subpart.isdigit():
		self._number = int(subpart)
		break
		continue
]:
	i: 0(t)
	o: 100()

nname: 0
n 0(self._number is None)[]:
	i: 
	o: 15(t), 100(f)

nname: 0
n 0(None)[if self._number is None:
	full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
	for subpart in reversed(full_uri.split('/')):
		if subpart.isdigit():
			self._number = int(subpart)
			break
			continue
return self._number
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a4ec>}
nname: 45
n 45(None)[return self._pic_uri
]:
	i: 22(), 44()
	o: 

nname: 44
n 44(None)[]:
	i: 0&15(f)
	o: 45()

nname: 22
n 22(None)[self._pic_uri = self._find_prefixed_uri('Image URL (for hotlinking/embedding):')
]:
	i: 0&15(t)
	o: 45()

nname: 0&15
n 0&15(self._pic_uri is None or force_refresh)[]:
	i: 
	o: 22(t), 44(f)

nname: 0&15
n 0&15(None)[if self._pic_uri is None or force_refresh:
	self._pic_uri = self._find_prefixed_uri('Image URL (for hotlinking/embedding):')
return self._pic_uri
]:
	i: 
	o: 

self.nodes: {'0&15': <unpyclib.structure.node instance at 0xb754a8ac>}
nname: 6
n 6(None)[__doc__ = '\n    XKCD Images informations fetcher\n    works by downloading pages and parsing data\n    '
base_site = 'http://%sxkcd.com/'
def __init__(self, base=None, **kw):
	if base is None:
		base = 'comic/random'
		prefix = 'dynamic.'
		name = 'Random Episode'
		self._number = None
	else:
		if isinstance(base, int):
			base = str(base)
			self._number = base
		else:
			self._number = None
		prefix = ''
		if base:
			pass
		name = 'Latest'
	uri = self.base_site % prefix + base
	if uri[-1] != '/':
		uri += '/'
	self.uri = uri
	self._pic_uri = None
	ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
	return None

def __repr__(self):
	return '<%s %s>' % (self.name, self.__class__.__name__)

def _get_data(self):
	site = urllib.urlopen(self.uri)
	return site.read()

def _find_prefixed_uri(self, prefix, lookup_size=500):
	data = self._get_data()
	idx = data.index(prefix) + len(prefix)
	substring = data[idx:idx + lookup_size]
	return substring[substring.index('http'):substring.index('</')]

def get_number(self):
	if self._number is None:
		full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
		for subpart in reversed(full_uri.split('/')):
			if subpart.isdigit():
				self._number = int(subpart)
				break
				continue
	return self._number

def get_uri(self, force_refresh=False):
	if self._pic_uri is None or force_refresh:
		self._pic_uri = self._find_prefixed_uri('Image URL (for hotlinking/embedding):')
	return self._pic_uri

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7548c8c>}
nname: 75
n 75(None)[return None
]:
	i: 43(), 74()
	o: 

nname: 74
n 74(None)[]:
	i: 0(f)
	o: 75()

nname: 43
n 43(None)[latest = XkcdImg('')
XkcdFolder._Max = latest.get_number()
]:
	i: 0(t)
	o: 75()

nname: 0
n 0(XkcdFolder._Max is None)[GenericContainer.__init__(self, name='XKCD webcomic', type_='dir', **kw)
]:
	i: 
	o: 43(t), 74(f)

nname: 0
n 0(None)[GenericContainer.__init__(self, name='XKCD webcomic', type_='dir', **kw)
if XkcdFolder._Max is None:
	latest = XkcdImg('')
	XkcdFolder._Max = latest.get_number()
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754af0c>}
nname: 6
n 6(None)[__doc__ = '\n    Class showing XkcdImg use\n    '
__metaclass__ = MetaSingleton
_Max = None
def __init__(self, **kw):
	GenericContainer.__init__(self, name='XKCD webcomic', type_='dir', **kw)
	if XkcdFolder._Max is None:
		latest = XkcdImg('')
		XkcdFolder._Max = latest.get_number()
	return None

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7548f6c>}
nname: 0
n 0(None)[return cook_opener.open('http://youporn.com/' + opts).read()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75485cc>}
nname: 0
n 0(None)[self.vid_id = video_id
self.thumb = thumb
self._uri = None
VideoItem.__init__(self, title, uri=self.get_uri, thumbnail=thumb, **kw)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a96c>}
nname: 64
n 64(None)[return self._uri
]:
	i: 15(), 63()
	o: 

nname: 63
n 63(None)[]:
	i: 0(f)
	o: 64()

nname: 15
n 15(None)[site = get_site('watch/' + self.vid_id)
self._uri = self.flv_re.findall(site)[0]
]:
	i: 0(t)
	o: 64()

nname: 0
n 0(self._uri is None)[]:
	i: 
	o: 15(t), 63(f)

nname: 0
n 0(None)[if self._uri is None:
	site = get_site('watch/' + self.vid_id)
	self._uri = self.flv_re.findall(site)[0]
return self._uri
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754a16c>}
nname: 0
n 0(None)[return self.thumb
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7548bcc>}
nname: 6
n 6(None)[flv_re = re.compile('"([^"]+?\\.flv)"')
def __init__(self, video_id, thumb, title, **kw):
	self.vid_id = video_id
	self.thumb = thumb
	self._uri = None
	VideoItem.__init__(self, title, uri=self.get_uri, thumbnail=thumb, **kw)
	return None

def get_uri(self):
	if self._uri is None:
		site = get_site('watch/' + self.vid_id)
		self._uri = self.flv_re.findall(site)[0]
	return self._uri

def get_thumbnail(self):
	return self.thumb

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb754880c>}
nname: 0
n 0(None)[self._re = re.compile('<a href="/watch/(\\d+)"\\s+class="thumblink"><img id="thumb\\d+" src="([^"]+)".*?class="thumb"\\s*[/<>a\\s]+<p\\s+class="title">[^>]+>(.*?)</a>')
self.page = str(page)
GenericContainer.__init__(self, name='YouPorn', type_='dir', **kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754ab6c>}
nname: 6
n 6(None)[def __init__(self, page=1, **kw):
	self._re = re.compile('<a href="/watch/(\\d+)"\\s+class="thumblink"><img id="thumb\\d+" src="([^"]+)".*?class="thumb"\\s*[/<>a\\s]+<p\\s+class="title">[^>]+>(.*?)</a>')
	self.page = str(page)
	GenericContainer.__init__(self, name='YouPorn', type_='dir', **kw)

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb754868c>}
nname: 0
n 0(None)[AudioItem.__init__(self, kw['name'], uri='http://www.shoutcast.com/sbin/tunein-station.pls?id=%s' % kw['id'])
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754898c>}
nname: 6
n 6(None)[def __init__(self, **kw):
	AudioItem.__init__(self, kw['name'], uri='http://www.shoutcast.com/sbin/tunein-station.pls?id=%s' % kw['id'])

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb754868c>}
nname: 0
n 0(None)[self.genre = kw.pop('name')
GenericContainer.__init__(self, name=self.genre, type_='dir', **kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7548f4c>}
nname: 6
n 6(None)[def __init__(self, **kw):
	self.genre = kw.pop('name')
	GenericContainer.__init__(self, name=self.genre, type_='dir', **kw)

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7548ecc>}
nname: 0
n 0(None)[GenericContainer.__init__(self, name='Shoutcast', type_='dir', **kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb754872c>}
nname: 6
n 6(None)[def __init__(self, **kw):
	GenericContainer.__init__(self, name='Shoutcast', type_='dir', **kw)

browse = cache_result(600)()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb754870c>}
nname: 0
n 0(None)[from __future__ import absolute_import
from ..containers import GenericContainer
from .core import ImageItem, AudioItem, VideoItem
import urllib
from peewee.cache_utils import cache_result
from peewee.misc_utils import MetaSingleton
from peewee.debug import GET_LOGGER
log = GET_LOGGER(__name__)
class DilbertYearFolder(GenericContainer):
	def __init__(self, year, type_='dir', **kw):
		GenericContainer.__init__(self, str(year), type_=type_, **kw)
		self.year = year

	def browse(self):
		pass



class DilbertFolder(GenericContainer):
	def __init__(self):
		GenericContainer.__init__(self, 'Dilbert comics', type_='dir')

	browse = cache_result(600)()


class MLCFolder(GenericContainer):
	__metaclass__ = MetaSingleton
	max_idx = 290
	base_uri = 'http://monsieur-le-chien.fr/'
	uri = base_uri + 'index.php?planche='
	def __init__(self, **kw):
		GenericContainer.__init__(self, 'Monsieur le chien', type_='dir', **kw)

	def _num2jpg(self, num):
		real_uri = self.uri + str(num)
		web = urllib.urlopen(real_uri)
		data = web.read()
		try:
			idx = data.index('i/planches/')
		except ValueError:
			print 'No data'
		return self.base_uri + data[idx:].split('"', 1)[0]

	browse = cache_result(600)()


class XkcdImg(ImageItem):
	__doc__ = '\n    XKCD Images informations fetcher\n    works by downloading pages and parsing data\n    '
	base_site = 'http://%sxkcd.com/'
	def __init__(self, base=None, **kw):
		if base is None:
			base = 'comic/random'
			prefix = 'dynamic.'
			name = 'Random Episode'
			self._number = None
		else:
			if isinstance(base, int):
				base = str(base)
				self._number = base
			else:
				self._number = None
			prefix = ''
			if base:
				pass
			name = 'Latest'
		uri = self.base_site % prefix + base
		if uri[-1] != '/':
			uri += '/'
		self.uri = uri
		self._pic_uri = None
		ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
		return None

	def __repr__(self):
		return '<%s %s>' % (self.name, self.__class__.__name__)

	def _get_data(self):
		site = urllib.urlopen(self.uri)
		return site.read()

	def _find_prefixed_uri(self, prefix, lookup_size=500):
		data = self._get_data()
		idx = data.index(prefix) + len(prefix)
		substring = data[idx:idx + lookup_size]
		return substring[substring.index('http'):substring.index('</')]

	def get_number(self):
		if self._number is None:
			full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
			for subpart in reversed(full_uri.split('/')):
				if subpart.isdigit():
					self._number = int(subpart)
					break
					continue
		return self._number

	def get_uri(self, force_refresh=False):
		if self._pic_uri is None or force_refresh:
			self._pic_uri = self._find_prefixed_uri('Image URL (for hotlinking/embedding):')
		return self._pic_uri



class XkcdFolder(GenericContainer):
	__doc__ = '\n    Class showing XkcdImg use\n    '
	__metaclass__ = MetaSingleton
	_Max = None
	def __init__(self, **kw):
		GenericContainer.__init__(self, name='XKCD webcomic', type_='dir', **kw)
		if XkcdFolder._Max is None:
			latest = XkcdImg('')
			XkcdFolder._Max = latest.get_number()
		return None

	browse = cache_result(600)()


import re
import urllib2
cook_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
def get_site(opts=''):
	return cook_opener.open('http://youporn.com/' + opts).read()

class YoupornVideo(VideoItem):
	flv_re = re.compile('"([^"]+?\\.flv)"')
	def __init__(self, video_id, thumb, title, **kw):
		self.vid_id = video_id
		self.thumb = thumb
		self._uri = None
		VideoItem.__init__(self, title, uri=self.get_uri, thumbnail=thumb, **kw)
		return None

	def get_uri(self):
		if self._uri is None:
			site = get_site('watch/' + self.vid_id)
			self._uri = self.flv_re.findall(site)[0]
		return self._uri

	def get_thumbnail(self):
		return self.thumb



class YoupornFolder(GenericContainer):
	def __init__(self, page=1, **kw):
		self._re = re.compile('<a href="/watch/(\\d+)"\\s+class="thumblink"><img id="thumb\\d+" src="([^"]+)".*?class="thumb"\\s*[/<>a\\s]+<p\\s+class="title">[^>]+>(.*?)</a>')
		self.page = str(page)
		GenericContainer.__init__(self, name='YouPorn', type_='dir', **kw)

	browse = cache_result(600)()


import xml.etree.ElementTree as ET
class ShoutCastRadio(AudioItem):
	def __init__(self, **kw):
		AudioItem.__init__(self, kw['name'], uri='http://www.shoutcast.com/sbin/tunein-station.pls?id=%s' % kw['id'])



class ShoutCastGenreFolder(GenericContainer):
	def __init__(self, **kw):
		self.genre = kw.pop('name')
		GenericContainer.__init__(self, name=self.genre, type_='dir', **kw)

	browse = cache_result(600)()


class ShoutCastFolder(GenericContainer):
	def __init__(self, **kw):
		GenericContainer.__init__(self, name='Shoutcast', type_='dir', **kw)

	browse = cache_result(600)()


]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7535eac>}
from __future__ import absolute_import
from ..containers import GenericContainer
from .core import ImageItem, AudioItem, VideoItem
import urllib
from peewee.cache_utils import cache_result
from peewee.misc_utils import MetaSingleton
from peewee.debug import GET_LOGGER
log = GET_LOGGER(__name__)
class DilbertYearFolder(GenericContainer):
	def __init__(self, year, type_='dir', **kw):
		GenericContainer.__init__(self, str(year), type_=type_, **kw)
		self.year = year

	def browse(self):
		pass



class DilbertFolder(GenericContainer):
	def __init__(self):
		GenericContainer.__init__(self, 'Dilbert comics', type_='dir')

	browse = cache_result(600)()


class MLCFolder(GenericContainer):
	__metaclass__ = MetaSingleton
	max_idx = 290
	base_uri = 'http://monsieur-le-chien.fr/'
	uri = base_uri + 'index.php?planche='
	def __init__(self, **kw):
		GenericContainer.__init__(self, 'Monsieur le chien', type_='dir', **kw)

	def _num2jpg(self, num):
		real_uri = self.uri + str(num)
		web = urllib.urlopen(real_uri)
		data = web.read()
		try:
			idx = data.index('i/planches/')
		except ValueError:
			print 'No data'
		return self.base_uri + data[idx:].split('"', 1)[0]

	browse = cache_result(600)()


class XkcdImg(ImageItem):
	__doc__ = '\n    XKCD Images informations fetcher\n    works by downloading pages and parsing data\n    '
	base_site = 'http://%sxkcd.com/'
	def __init__(self, base=None, **kw):
		if base is None:
			base = 'comic/random'
			prefix = 'dynamic.'
			name = 'Random Episode'
			self._number = None
		else:
			if isinstance(base, int):
				base = str(base)
				self._number = base
			else:
				self._number = None
			prefix = ''
			if base:
				pass
			name = 'Latest'
		uri = self.base_site % prefix + base
		if uri[-1] != '/':
			uri += '/'
		self.uri = uri
		self._pic_uri = None
		ImageItem.__init__(self, name, uri=self.get_uri, thumbnail=self.get_uri, **kw)
		return None

	def __repr__(self):
		return '<%s %s>' % (self.name, self.__class__.__name__)

	def _get_data(self):
		site = urllib.urlopen(self.uri)
		return site.read()

	def _find_prefixed_uri(self, prefix, lookup_size=500):
		data = self._get_data()
		idx = data.index(prefix) + len(prefix)
		substring = data[idx:idx + lookup_size]
		return substring[substring.index('http'):substring.index('</')]

	def get_number(self):
		if self._number is None:
			full_uri = self._find_prefixed_uri('Permanent link to this comic: ')
			for subpart in reversed(full_uri.split('/')):
				if subpart.isdigit():
					self._number = int(subpart)
					break
					continue
		return self._number

	def get_uri(self, force_refresh=False):
		if self._pic_uri is None or force_refresh:
			self._pic_uri = self._find_prefixed_uri('Image URL (for hotlinking/embedding):')
		return self._pic_uri



class XkcdFolder(GenericContainer):
	__doc__ = '\n    Class showing XkcdImg use\n    '
	__metaclass__ = MetaSingleton
	_Max = None
	def __init__(self, **kw):
		GenericContainer.__init__(self, name='XKCD webcomic', type_='dir', **kw)
		if XkcdFolder._Max is None:
			latest = XkcdImg('')
			XkcdFolder._Max = latest.get_number()
		return None

	browse = cache_result(600)()


import re
import urllib2
cook_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
def get_site(opts=''):
	return cook_opener.open('http://youporn.com/' + opts).read()

class YoupornVideo(VideoItem):
	flv_re = re.compile('"([^"]+?\\.flv)"')
	def __init__(self, video_id, thumb, title, **kw):
		self.vid_id = video_id
		self.thumb = thumb
		self._uri = None
		VideoItem.__init__(self, title, uri=self.get_uri, thumbnail=thumb, **kw)
		return None

	def get_uri(self):
		if self._uri is None:
			site = get_site('watch/' + self.vid_id)
			self._uri = self.flv_re.findall(site)[0]
		return self._uri

	def get_thumbnail(self):
		return self.thumb



class YoupornFolder(GenericContainer):
	def __init__(self, page=1, **kw):
		self._re = re.compile('<a href="/watch/(\\d+)"\\s+class="thumblink"><img id="thumb\\d+" src="([^"]+)".*?class="thumb"\\s*[/<>a\\s]+<p\\s+class="title">[^>]+>(.*?)</a>')
		self.page = str(page)
		GenericContainer.__init__(self, name='YouPorn', type_='dir', **kw)

	browse = cache_result(600)()


import xml.etree.ElementTree as ET
class ShoutCastRadio(AudioItem):
	def __init__(self, **kw):
		AudioItem.__init__(self, kw['name'], uri='http://www.shoutcast.com/sbin/tunein-station.pls?id=%s' % kw['id'])



class ShoutCastGenreFolder(GenericContainer):
	def __init__(self, **kw):
		self.genre = kw.pop('name')
		GenericContainer.__init__(self, name=self.genre, type_='dir', **kw)

	browse = cache_result(600)()


class ShoutCastFolder(GenericContainer):
	def __init__(self, **kw):
		GenericContainer.__init__(self, name='Shoutcast', type_='dir', **kw)

	browse = cache_result(600)()


